let append = document.querySelector('.append');
let decrease = document.querySelector('.decrease');
let delete_ = document.querySelector('.delete');
let login_bg = document.querySelector('.login-bg');
let pop_window = document.querySelector('#pop-window');
let pop_window3 = document.querySelector('#pop-window3');
let pop_window2 = document.querySelector('#pop-window2');
let close = document.querySelector('#close1');
let close3 = document.querySelector('#close2');
let close2 = document.querySelector('.close2');
let cancel_operate1 = document.querySelector('.cancel-operate1');
let cancel_operate2 = document.querySelector('.cancel-operate2');
let index = 0;
let append_operate = document.querySelector('#append-operate');
let decrease_operate = document.querySelector('#decrease-operate');
let delete_operate = document.querySelector('#delete-operate');

let operate_input = document.querySelector('#operate-input');
let current_surplus = document.querySelector('#current-surplus');
let result_surplus = document.querySelector('#result-surplus');
let operate_input2 = document.querySelector('#operate-input2');
let current_surplus2 = document.querySelector('#current-surplus2');
let result_surplus2 = document.querySelector('#result-surplus2');
append.addEventListener('click',function(){
    // index = 0;
    append_operate.style.display = 'inline-block';
    login_bg.style.display = 'block';
    pop_window.style.display = 'block';
})
decrease.addEventListener('click',function(){
    // index = 1;
    decrease_operate.style.display = 'inline-block';
    login_bg.style.display = 'block';
    pop_window3.style.display = 'block';
})
delete_.addEventListener('click',function(){
    delete_operate.style.display = 'inline-block';
    login_bg.style.display = 'block';
    pop_window2.style.display = 'block';
})
close.addEventListener('click',function(){
    append_operate.style.display = 'none';
    // decrease_operate.style.display = 'none';
    login_bg.style.display = 'none';
    pop_window.style.display = 'none';
})
close3.addEventListener('click',function(){
    // delete_operate.style.display = 'none';
    decrease_operate.style.display = 'none';
    login_bg.style.display = 'none';
    pop_window3.style.display = 'none';
})
close2.addEventListener('click',function(){
    delete_operate.style.display = 'none';
    login_bg.style.display = 'none';
    pop_window2.style.display = 'none';
})
cancel_operate1.addEventListener('click',function(){
    append_operate.style.display = 'none';
    decrease_operate.style.display = 'none';
    login_bg.style.display = 'none';
    pop_window.style.display = 'none';
    pop_window3.style.display = 'none';
})
cancel_operate2.addEventListener('click',function(){
    delete_operate.style.display = 'none';
    login_bg.style.display = 'none';
    pop_window2.style.display = 'none';
})


operate_input.addEventListener('keyup',function (){
    result_surplus.innerText = Number(current_surplus.innerText) + Number(operate_input.value);
})
append_operate.addEventListener('click',function(){
    let resultNum = result_surplus.innerText;
    $.ajax({
        type :'GET',
        url :'http://localhost:8080/catalog/appendNum?resultNum='+resultNum,
        success:function (data){
            console.log(data)
        },
        error:function (errorMsg){
            console.log(errorMsg)
        }
    });
})

operate_input2.addEventListener('keyup',function (){
    result_surplus2.innerText = Number(current_surplus2.innerText) - Number(operate_input2.value);
})
decrease_operate.addEventListener('click',function(){
    let resultNum = result_surplus2.innerText;
    $.ajax({
        type :'GET',
        url :'http://localhost:8080/catalog/decreaseNum?resultNum='+resultNum,
        success:function (data){
            console.log(data)
        },
        error:function (errorMsg){
            console.log(errorMsg)
        }
    });
})

let itemId = document.querySelector('#itemId');
delete_operate.addEventListener('click',function(){
    $.ajax({
        type :'GET',
        url :'http://localhost:8080/deleteItem?itemId='+itemId.innerText,
        success:function (data){
            console.log(data)
        },
        error:function (errorMsg){
            console.log(errorMsg)
        }
    });
})

let reviseItem = document.querySelector('#reviseItem');
let close4 = document.querySelector('.close3');
let edit_item_detail = document.querySelector('.edit_item_detail');
let cancel = document.querySelector('#cancel');
cancel.addEventListener('click',function (){
    edit_item_detail.style.display = 'none';
    login_bg.style.display = 'none';
})
reviseItem.addEventListener('click',function (){
    edit_item_detail.style.display = 'block';
    login_bg.style.display = 'block';
})
close4.addEventListener('click',function (){
    edit_item_detail.style.display = 'none';
    login_bg.style.display = 'none';

})